﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using DBA.Data;
using DBA.Data.ADO;

namespace Demo
{
    public partial class demo_page4Modify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            BindDate();
        }

       DataAccessLibrary dal = CommonQuery.DataAccessLibrary;

        private void BindDate()
        {
            string sql = "";
            dal.ManagerParameter.ClearParameter();
            if (Request.Params["id"] != null)
            {
                ViewState["UserID"] = Request.Params["id"].Trim();
                dal.ManagerParameter.AddNewInParameter("UserID", ViewState["UserID"].ToString());
                sql = "SELECT * FROM test_UserInfo WHERE UserID = @UserID";
                String[] values = dal.ExecuteStringsBySingleRow(sql);
                txtAddress.Text = values[2];
                txtEmail.Text = values[6];
                txtIDCard.Text = values[3];
                txtPhone.Text = values[4];
                txtPostalCode.Text = values[7];
                txtUserName.Text = values[1];
                txtMobile.Text = values[5];
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

        }

        protected void lbtn_Save_Click(object sender, EventArgs e)
        {

            dal.ManagerParameter.ClearParameter();
            dal.ManagerParameter.AddNewInParameter("UserName", txtUserName.Text.Trim());
            dal.ManagerParameter.AddNewInParameter("Address", txtAddress.Text.Trim());
            dal.ManagerParameter.AddNewInParameter("IDcard", txtIDCard.Text.Trim());
            dal.ManagerParameter.AddNewInParameter("Phone", txtPhone.Text.Trim());
            dal.ManagerParameter.AddNewInParameter("Mobile", txtMobile.Text.Trim());
            dal.ManagerParameter.AddNewInParameter("Email", txtEmail.Text.Trim());
            dal.ManagerParameter.AddNewInParameter("PostalCode", txtPostalCode.Text.Trim());
            dal.ModifyData.Update("test_UserInfo", "UserID=" + ViewState["UserID"].ToString());
            if (String.IsNullOrEmpty(dal.ErrorMessage))
            {
                ScriptManager.RegisterStartupScript(this, base.GetType(), "updateOk" + System.Guid.NewGuid().ToString(), "Public.OpertAlert('数据修改成功',true);", true);
            }
            else
            {
            }
        }
    }
}